<template>
	<view class="list">
		<view v-for="(item,index) in list" :key="index" @click="toRoute('/pages-home/service/detail?id='+item.id)">
			<view class="item flex">
				<uv-image :src="item.image" width="70px" height="70px" />
				<view class="info w-full">
					<view class="title">{{item.store_name}}</view>
					<view class="make">免费预约</view>
					<view class="flex">
						<text class="cost">已售{{item.sales}}</text>
						<text class="cost" style="margin-left: 30rpx;">好评率96%</text>
					</view>
				</view>
			</view>
			<uv-gap height="30rpx" bgColor="#F6F4F7"></uv-gap>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		getIconPath
	} from '@/util'
	import {
		getListByCate
	} from '@/api'
	import {
		onLoad,
		onReachBottom
	} from '@dcloudio/uni-app'
	const keyword = ref('')
	const page = ref(1)
	const list = ref([])
	const total = ref(0)
	const finished = ref(false)
	const toRoute = (url) => uni.navigateTo({ url })
	const getList = async () => {
		finished.value = false;
		if (page.value === 1) list.value = []
		const {result} = await getListByCate({
			page: page.value,
			limit: 10,
			name: keyword.value,
		})
		page.value++
		total.value = result.total
		list.value = [...list.value, ...result.data]
		finished.value = list.value.length >= result.total;
	}
	onReachBottom(() => {
		if (finished.value) return
		getList()
	})
	onLoad((option) => {
		keyword.value = decodeURIComponent(option.keyword)
		getList()
	})
</script>

<style lang="scss" scoped>
	.list {
		margin: 30rpx;

		.item {
			padding: 30rpx;
			border-radius: 10rpx;
			box-sizing: border-box;
			background-color: #fff;

			.info {
				display: flex;
				margin-left: 30rpx;
				flex-direction: column;
				justify-content: space-between;

				.title {
					color: #333333;
					font-size: 30rpx;
					font-weight: 700;
				}

				.make {
					color: #E59D37;
					font-size: 28rpx;
					font-weight: 400;
				}

				.cost {
					color: #C3C3C5;
					font-size: 20rpx;
				}
			}
		}
	}
</style>